package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.SaleBean;
import com.project.service.ISaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("sale")
public class SaleController {
    @Autowired
    private ISaleService service;
@RequestMapping("add")
    public String add(Integer userId, String user, String address, Integer totalPrice, Integer clientId){
    SaleBean saleBean = new SaleBean(user,address,totalPrice,clientId);
        service.add(userId,saleBean);
        return "ok";
    }
@RequestMapping("findByItem")
    public IPage<SaleBean> findByItem(Integer pageNo, String clientName, @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate){
    return service.findByItem(pageNo,clientName,startDate,endDate);
    }
@RequestMapping("findById")
    public SaleBean findById(Integer id){
    return service.findByID(id);
    }
}
